<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
  <meta charset="UTF-8"/>
  <meta name="renderer" content="webkit"/>
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
  <meta http-equiv="Pragma" content="no-cache"/>
  <meta http-equiv="Cache-Control" content="no-cache,must-revalidate"/>
  <meta http-equiv="Expires" content="web,26 Feb 1997 08:21:57GMT"/>
  <meta http-equiv="Cache" content="no-cache"/>
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
  <title>错题卡记录列表</title>
  <th:block th:include="common/pub_head :: default"></th:block>
  <th:block th:include="common/pub_head :: layui"></th:block>
  <style>
    .layui-table-view {
      margin-top: 0px;
    }

    .right {
      text-align: right;
    }

    .left {
      text-align: left;
    }
  </style>
</head>
<body class="layui-col-md-offset1 layui-col-md10">
<div class="layui-card-header" style="margin-bottom: 5px">
  <h2>答题记录列表</h2>
</div>
<form action="" class="layui-form" id="list_form">
  <div class="layui-form-item">

    <div class="layui-inline">
      <label class="layui-form-label">隶属类型</label>
      <div class="layui-input-inline">
        <select name="answerType" id="answerType" lay-filter="answerType">
          <option value="">请选择...</option>
          <th:block th:each="answerType : ${answerTypeList}">
            <option th:value="${answerType.dicKey}" th:text="${answerType.dicValue}"></option>
          </th:block>
        </select>
      </div>
    </div>

    <div class="layui-inline">
      <label class="layui-form-label">试卷标题</label>
      <div class="layui-input-inline">
        <input type="text" name="title" id="title" placeholder="请输入试卷标题" autocomplete="off" class="layui-input"/>
      </div>

      <button class="layui-btn pull-right" type="button" onclick="listAnswerLogByParam()">搜索</button>
      <button class="layui-btn pull-right" type="button" onclick="clearForm()" style="margin-left: 10px">清空</button>
    </div>
  </div>
</form>
<!-- 数据列表-->
<table class="layui-table" lay-filter="demo" id="answerCardList" style="margin: 0px; width: 100%;"></table>
<div id="content" style="display: none;">
  <div class="layui-row" style="padding: 4px 5px">
    <div class="layui-col-md6 right">
      <span>题库标题：</span>
    </div>
    <div class="layui-col-md6 left">
      <span name="title">题库标题</span>
    </div>
  </div>
  <div class="layui-row" style="text-align: center;padding: 4px 5px">
    <a href="" style="color: #1E9FFF">前往查看>></a>
  </div>
</div>
<script type="text/html" id="toolbarDemo">
  <div class="layui-btn-container">
    <button class="layui-btn layui-btn-sm layui-btn-normal" lay-event="createErrorAnswerCard">生成错题卡</button>
    <button class="layui-btn layui-btn-sm layui-btn-danger" lay-event="batchDel">批量删除</button>
  </div>
</script>
<!--表格操作-->
<script type="text/html" id="barDemo">
  <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>
<script>
  /*<![CDATA[*/
  function batchDelAnswerLog(selectId) {
    var URL = path + "/answer/log/batchDelAnswerLog";
    var formData = {
      selectId: selectId + "",
    };
    $.post(URL, formData, function (jsonData) {
      var flag = jsonData.flag;
      if (flag) {
        layer.alert("删除成功");
        listAnswerLogByParam();
      } else {
        layer.alert("删除失败，错误信息为: " + jsonData.errroMsg);
      }
    }, "json");
  }

  function createErrorAnswerCard(selectId) {
    var URL = path + "/answer/createErrorAnswerCard";
    var formData = {
      answerLogIdList: selectId + ""
    };
    $.post(URL, formData, function (jsonData) {
      if (jsonData.flag) {
        var answerCardBean = jsonData.answerCardBean;
        var URL = path + "/answer/study/" + answerCardBean.id;
        var content = answerCardBean.title + "已经生成<br />前往查看<a href='" + URL + "' style='color: #1E9FFF'>前往查看>></a>";
        layer.alert(content);
      } else {
        layer.alert("生成错误，错误信息为: " + jsonData.errorMsg);
      }
    }, "json");
  }

  /*]]>*/
</script>
<script>
  /*<![CDATA[*/
  var table;
  $(function () {
    layui.use(['table', 'form'], function () {
      table = layui.table;

      table.render({
        elem: '#answerCardList',
        id: 'answerCardList',
        toolbar: '#toolbarDemo',
        url: path + '/answer/log/listAnswerLogByParam',
        cols: [[
          {type: 'checkbox', field: "id", fixed: 'left'},
          {field: 'answerCardTitle', title: '试卷标题', minWidth: 200},
          {field: 'answerTypeName', title: '题库类型', width: 150},
          {
            title: '单选正确率', width: 115, templet: function (d) {
              var span = $('<span style="color: #bbb"></span>');
              span.text(d.singleCorrect + '/' + d.singleCount);
              var percent = d.singleCorrect / d.singleCount;
              return percentHandler(percent) + '%&emsp;' + span.prop('outerHTML');
            }
          },
          {
            title: '多选正确率', width: 115, templet: function (d) {
              var span = $('<span style="color: #bbb"></span>');
              span.text(d.multiCorrect + '/' + d.multiCount);
              var percent = d.multiCorrect / d.multiCount;
              return percentHandler(percent) + '%&emsp;' + span.prop('outerHTML');
            }
          },
          {
            title: '填空正确率', width: 115, templet: function (d) {
              var span = $('<span style="color: #bbb"></span>');
              span.text(d.fillBlankCorrect + '/' + d.fillBlankCount);
              var percent = d.fillBlankCorrect / d.fillBlankCount;
              return percentHandler(percent) + '%&emsp;' + span.prop('outerHTML');
            }
          },
          {
            title: '判断正确率', width: 115, templet: function (d) {
              var span = $('<span style="color: #bbb"></span>');
              span.text(d.judgeCorrect + '/' + d.judgeCount);
              var percent = d.judgeCorrect / d.judgeCount;
              return percentHandler(percent) + '%&emsp;' + span.prop('outerHTML');
            }
          },
          {
            title: '总正确率(除简答)', width: 140, templet: function (d) {
              var span = $('<span style="color: #bbb"></span>');
              span.text(d.totalCorrect + '/' + d.totalCount);
              var percent = d.totalCorrect / d.totalCount;
              return percentHandler(percent) + '%&emsp;' + span.prop('outerHTML');
            }
          },
          {field: 'createTime', title: '创建时间', width: 160},
          {fixed: 'right', title: '操作', toolbar: '#barDemo', width: 65}
        ]],
        request: {
          pageName: 'pn',
          limitName: 'pageSize' //每页数据量的参数名，默认：limit
        },
        page: true
      });

      //头工具栏事件
      table.on('toolbar(demo)', function (obj) {
        var checkStatus = table.checkStatus(obj.config.id);
        switch (obj.event) {
          case 'batchDel':
            var data = checkStatus.data;
            var selectId = [];
            $.each(data, function (index, domEle) {
              selectId.push(domEle.id);
            });
            if (selectId.length == 0) {
              layer.alert("请先选择数据");

              return;
            }
            layer.confirm('真的删除数据么', function (index) {
              batchDelAnswerLog(selectId);
            });

            break;
          case 'createErrorAnswerCard':
            var data = checkStatus.data;
            var selectId = [];
            $.each(data, function (index, domEle) {
              selectId.push(domEle.id);
            });
            if (selectId.length == 0) {
              layer.alert("请先选择数据");

              return;
            }
            createErrorAnswerCard(selectId);
        }
      });

      table.on('tool(demo)', function (obj) {
        var data = obj.data;
        var selectId = [data.id];
        if (obj.event === 'del') {
          layer.confirm('真的删除数据么', function (index) {
            batchDelAnswerLog(selectId);
            layer.close(index);
          });
        }
      });

    });
  });

  document.onkeydown = EnterLogin;

  function EnterLogin(event) {
    if (event.keyCode == 13) {
      listAnswerLogByParam();
    }
  }

  function clearForm() {
    $("#list_form")[0].reset();
  }

  var index = 0;

  function listAnswerLogByParam() {
    layer.close(index);
    table.reload('answerCardList', {
      page: {
        curr: 1 //重新从第 1 页开始
      },
      where: {
        title: $("#title").val(),
        answerType: $("#answerType").val()
      }
    });
  }

  /*]]>*/
</script>
<script>
  /*<![CDATA[*/
  function mergeColumn(columnNum) {
    if ($("table.layui-table tr").length > 0) {
      var tdStrCur = "";
      var countCur = 0;
      var countNext = 0;
      var flag = false;
      var objCur;
      var objNext;
      $("table.layui-table tr").each(function () {
        if ($(this).find("td").eq(columnNum).find("div").text() != tdStrCur) {
          tdStrCur = $(this).find("td").eq(columnNum).text();
          countCur = 1;
          flag = true;
          objCur = $(this).find("td").eq(columnNum);
        } else if (objCur) {
          if ($(this).find("td").eq(columnNum).find("div").text() != "") {
            $(this).find("td").eq(columnNum).remove();
            countCur++;
            flag = false;
            objNext = objCur;
            countNext = countCur;
          }
        }
        if (flag && countCur != 1) {
          objNext.attr("rowspan", countNext);
        } else {
          if (objCur) {
            objCur.attr("rowspan", countCur);
          }
        }
      });
      if (objCur) {
        objCur.attr("rowspan", countCur);
      }
    }
  }

  function percentHandler(percent) {
    percent = percent >= 0 ? percent * 100 : 100;
    var arr = percent.toString().split('.');
    if (arr.length == 2 && arr[1].length > 2) {
      percent = percent.toFixed(2);
    }
    return percent;
  }

  /*]]>*/
</script>
</body>
</html>
